package format

import (
	"context"
	"errors"

	"lab.com/define"
)

// GetContext .
func GetContext(ctx context.Context, logData LogData) context.Context {
	logger := NewLogger(LogInfo, logData)
	return context.WithValue(ctx, define.TranceSQLKey(define.LoggerKey), logger)
}

// GetLogger .
func GetLogger(ctx context.Context) (*LoggerLog, error) {
	logger, ok := ctx.Value(define.TranceSQLKey(define.LoggerKey)).(*LoggerLog)
	if ok {
		return logger, nil
	}
	return nil, errors.New("logger not found")
}
